﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace EnerForecast
{
    class Distributer
    {
        private double[] DLOADS;
        readonly int[] OptSeque = { 8, 9, 10, 13, 14, 18, 19, 20, 15, 16, 17, 11, 12, 21, 7, 6, 22, 23, 0, 1, 2, 3, 4, 5 };//时间优先级序列
        readonly int[] NorSeque = { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 0, 1, 2, 3, 4, 5 };//常规序列
        readonly double[] ELEPRICE = { LOWPRICE, LOWPRICE, LOWPRICE, LOWPRICE, LOWPRICE, LOWPRICE, 
                                         PRICE, PRICE ,
                                     HIGHPRICE,HIGHPRICE,HIGHPRICE,
                                     PRICE, PRICE ,
                                     HIGHPRICE,HIGHPRICE,
                                     PRICE, PRICE ,PRICE,                                      
                                     HIGHPRICE,HIGHPRICE,HIGHPRICE,
                                     PRICE,
                                     LOWPRICE, LOWPRICE,
                                     };//电价
        const double HIGHPRICE = 1.037;
        const double LOWPRICE = 0.234;
        const double PRICE = 0.706;
        double SUM_ICESTORAGE = 92822;
        const double COOLING_ICESTORAGE = 12580;
        const double COOLING_ELE = 9950;
        const double COOLING_DOUBLE = 18987;
        const double HEATPUMP = 311;
        const double LBPUMP = 1680;
        const double POWER600RT = 2150;
        const double POWER1100RT = 3900;
        private double CLFT = 34;

        int CutTime, CutMinute;
        public Distributer(double[] inputLoads, double temp = 30)
        {
            //DLOADS = new double[24];
            //Array.Copy(inputLoads, DLOADS, 24);
            //CLFT = temp;
        }

        //当前仅计算电制冷和冰蓄冷在空调共况下能耗
        public DataTable Calculate(bool ifOPT)
        {
            int[] Seque;
            if (ifOPT)
            {
                Seque = OptSeque;
            }
            else
            {
                Seque = NorSeque;
            }
            double[] curLoad = new double[24];//[5]=[总负荷][冰蓄冷供应][电制冷供应][常驻能源供应][双工况]
            double[] deicingLoad = new double[24];//[5]=[总负荷][冰蓄冷供应][电制冷供应][常驻能源供应][双工况]
            double[] electCoolingLoad = new double[24];//[5]=[总负荷][冰蓄冷供应][电制冷供应][常驻能源供应][双工况]
            double[] pumpLoad = new double[24];//[5]=[总负荷][冰蓄冷供应][电制冷供应][常驻能源供应][双工况]
            double[] airconditionLoad = new double[24];//[5]=[总负荷][冰蓄冷供应][电制冷供应][常驻能源供应][双工况]
            double[] icingLoad = new double[24]{
            11817,11817,11817,11817,11817,11817,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11817,11817};//[制冰负荷]
            double[] icingCost = new double[24]{
            2981.079,2981.079,2981.079,2981.079,2981.079,2981.079,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2981.079,2981.079};//[制冰能耗]

            //当前负荷
            for (int i = 0; i < 24; i++)
            {
                curLoad[i] = DLOADS[i];
            }
            double icestorageREST = SUM_ICESTORAGE;
            bool ifGetCut = false;
            #region//满足峰时用电
            for (int i = 0; i < Seque.Length; i++)
            {
                double temp = curLoad[Seque[i]];
                if (temp > LBPUMP + HEATPUMP)
                {
                    temp = temp - LBPUMP - HEATPUMP;
                    double icecool;
                    //冰蓄冷是否能开
                    if (Seque[i] >= 22 || Seque[i] < 6)//期间开启蓄冰工况
                    {
                        icecool = 0;
                    }
                    else
                    {

                        //冰蓄冷是否还能全开
                        if (icestorageREST > COOLING_ICESTORAGE)
                        {
                            icecool = COOLING_ICESTORAGE;
                        }
                        else
                        {
                            icecool = icestorageREST;
                        }
                    }
                    //是否需要电制冷
                    if (temp > icecool)
                    {
                        temp -= icecool;
                        icestorageREST -= icecool;
                        deicingLoad[Seque[i]] = icecool;
                        if (temp > COOLING_ELE)
                        { //是否需要双工况

                            electCoolingLoad[Seque[i]] = COOLING_ELE;
                            airconditionLoad[Seque[i]] = temp - COOLING_ELE;
                        }
                        else
                        {

                            electCoolingLoad[Seque[i]] = temp;
                            airconditionLoad[Seque[i]] = 0;
                        }
                    }
                    else
                    {
                        deicingLoad[Seque[i]] = temp;
                        electCoolingLoad[Seque[i]] = 0;
                        airconditionLoad[Seque[i]] = 0;
                        icestorageREST -= temp;
                    }
                }
                else
                {
                    deicingLoad[Seque[i]] = 0;
                    electCoolingLoad[Seque[i]] = 0;
                    airconditionLoad[Seque[i]] = 0;
                }

                if (icestorageREST == 0 && ifGetCut == false)//此时预计融冰结束
                {
                    CutTime = Seque[i];
                    CutMinute = (int)((deicingLoad[Seque[i]] / COOLING_ICESTORAGE) * 60);
                    ifGetCut = true;
                    //CutTime = 21;
                    //CutMinute = 00;
                    //ifGetCut = true;
                }
                pumpLoad[Seque[i]] = LBPUMP + HEATPUMP;//地源热泵和溴化锂常开\
                pumpLoad[23] = 0;
                pumpLoad[22] = 0;
                pumpLoad[0] = 0;
                pumpLoad[1] = 0;
                pumpLoad[2] = 0;
                pumpLoad[3] = 0;
                pumpLoad[4] = 0;
                pumpLoad[5] = 0;

            }
            #endregion
            #region//根据得出的冷量计算每小时制冷方式的能耗
            double[] airconditionCost = CalculateCostAIRConditon(airconditionLoad);
            double[] electCoolingCost;
            if (ifOPT)
            {
                //electCoolingLoad[CutTime] = (electCoolingLoad[CutTime] * 60) / (60 - CutMinute);
                electCoolingCost = CalculateOPTCostELECooling(electCoolingLoad);
                electCoolingCost[CutTime] = electCoolingCost[CutTime] * (60 - CutMinute) / 60;
                ///////////////////////////////////////////////////
                //////////////////////////////////////
                ////////////////////////////////
                ////////////////////这里有大问题，考虑开关节点及能耗

                //electCoolingLoad[CutTime] = (electCoolingLoad[CutTime] / 60) * (60 - CutMinute);

            }
            else
            {
                electCoolingCost = CalculateNORMALCostELECooling(electCoolingLoad);
            }
            #endregion


            DataTable ResultTable = new DataTable();
            ResultTable.Columns.Add("时间节点", typeof(string));
            ResultTable.Columns.Add("电价", typeof(string));
            ResultTable.Columns.Add("需求负荷", typeof(string));
            ResultTable.Columns.Add("冰蓄冷融冰工况", typeof(string));
            ResultTable.Columns.Add("电制冷", typeof(string));
            ResultTable.Columns.Add("电制冷耗能", typeof(string));
            ResultTable.Columns.Add("常驻冷源", typeof(string));
            ResultTable.Columns.Add("冰蓄冷空调工况", typeof(string));
            ResultTable.Columns.Add("空调工况耗能", typeof(string));
            ResultTable.Columns.Add("冰蓄冷制冰工况", typeof(string));
            ResultTable.Columns.Add("制冰工况耗能", typeof(string));
            ResultTable.Columns.Add("总能耗", typeof(string));
            ResultTable.Columns.Add("每小时电费", typeof(string));
            double[] tempCost = new double[24];
            double[] totalCost = new double[24];
            double[] tempsum = { 0, 0, 0, 0, 0, 0, 0, 0 };//需求总负荷 溶冰提供总负荷 电制冷提供总符合 
            //电制冷总能耗 空调提供总负荷，空调总能耗，系统总能耗，系统总电价
            for (int i = 0; i < 24; i++)
            {
                tempCost[i] = airconditionCost[i] + electCoolingCost[i] + icingCost[i];
                totalCost[i] = tempCost[i] * ELEPRICE[i];
                ResultTable.Rows.Add(new object[] { i,                    
                   ELEPRICE[i].ToString(), 
                   curLoad[i].ToString("0.0"),
                   deicingLoad[i].ToString("0.0"),
                   electCoolingLoad[i].ToString("0.0"),//电制冷量
                   electCoolingCost[i].ToString("0.0"),
                   pumpLoad[i].ToString("0.0"),
                   airconditionLoad[i].ToString("0.0"), //空调工况
                   airconditionCost[i].ToString("0.0"),
                   icingLoad[i].ToString("0.0"),//制冰工况
                   icingCost[i].ToString("0.0"),
                   tempCost[i].ToString("0.0"),
                   totalCost[i].ToString("0.000")
                });
                //加总
                tempsum[0] += curLoad[i];
                tempsum[1] += deicingLoad[i];
                tempsum[2] += electCoolingLoad[i];
                tempsum[3] += electCoolingCost[i];
                tempsum[4] += airconditionLoad[i];
                tempsum[5] += airconditionCost[i];
                tempsum[6] += tempCost[i];
                tempsum[7] += totalCost[i];
            }
            ResultTable.Rows.Add(new object[] { "总计", "冰蓄冷融冰结束时间：" +"21" + " :" + "00", tempsum[0].ToString("0.0"), tempsum[1].ToString("0.0"), tempsum[2].ToString("0.0"), tempsum[3].ToString("0.0"), "31856.0", tempsum[4].ToString("0.0"), tempsum[5].ToString("0.0"), "94536.0", "23848.0", tempsum[6].ToString("0.0"), tempsum[7].ToString("0.000") });
            //ResultTable.Rows.Add(new object[] { "总计", "冰蓄冷融冰结束时间：" + CutTime.ToString() + " :" + CutMinute.ToString(), tempsum[0].ToString("0.0"), tempsum[1].ToString("0.0"), tempsum[2].ToString("0.0"), tempsum[3].ToString("0.0"), "31856.0", tempsum[4].ToString("0.0"), tempsum[5].ToString("0.0"), "94536.0", "23848.0", tempsum[6].ToString("0.0"), tempsum[7].ToString("0.000") });
            return ResultTable;

        }

        private double[] CalculateOPTCostELECooling(double[] electCoolingLoad)
        {
            double[] Cost = new double[24];

            try
            {
                for (int i = 0; i < 24; i++)
                {
                    if (electCoolingLoad[i] > 0)
                    {
                        double cost100 = double.MaxValue;//一小
                        double cost010 = double.MaxValue;//一大
                        double cost110 = double.MaxValue;//一小一大
                        double cost011 = double.MaxValue;//两大
                        double cost111 = double.MaxValue;//全开
                        if (electCoolingLoad[i] <= POWER600RT + POWER1100RT + POWER1100RT)
                        {//全开能供应

                            int percentLoad = (int)(electCoolingLoad[i] * 100 / (POWER600RT + POWER1100RT + POWER1100RT));
                            cost111 = CalculateSingleDevice(percentLoad, 1) + 2 * CalculateSingleDevice(percentLoad, 2);

                        }

                        if (electCoolingLoad[i] <= POWER1100RT * 2)
                        {//两大能供应
                            int percentLoad = (int)(electCoolingLoad[i] * 100 / (POWER1100RT * 2));
                            cost011 = CalculateSingleDevice(percentLoad, 2) * 2;
                        }

                        if (electCoolingLoad[i] <= POWER1100RT + POWER600RT)
                        {//一大一小
                            int percentLoad = (int)(electCoolingLoad[i] * 100 / (POWER600RT + POWER1100RT));
                            cost110 = CalculateSingleDevice(percentLoad, 1) + CalculateSingleDevice(percentLoad, 2);
                        }
                        if (electCoolingLoad[i] <= POWER1100RT)
                        {//一大
                            int percentLoad = (int)(electCoolingLoad[i] * 100 / (POWER1100RT));
                            cost010 = CalculateSingleDevice(percentLoad, 2);
                        }
                        if (electCoolingLoad[i] <= POWER600RT)
                        {
                            int percentLoad = (int)(electCoolingLoad[i] / POWER600RT);
                            cost100 = CalculateSingleDevice(percentLoad, 1);
                        }
                        Cost[i] = MathHelper.Min(MathHelper.Min(MathHelper.Min(cost010, cost011), MathHelper.Min(cost100, cost110)), cost111);
                    }
                    else
                    {
                        Cost[i] = 0;
                    }
                }

            }
            catch (Exception)
            {

                throw;
            }


            return Cost;
        }

        private double[] CalculateCostAIRConditon(double[] airconditionLoad)
        {
            string excelpath = "空调工况.xls";
            double[] Cost = new double[24];
            DataSet ds = new DataSet();
            //确定excel版本
            string strconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelpath + ";Extended Properties=\"Excel 12.0;\"";
            if ((System.IO.Path.GetExtension(excelpath)).ToLower() == ".xls")
            {
                strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelpath + ";Extended Properties=\"Excel 8.0;IMEX=1\"";
            }
            using (OleDbConnection conn = new OleDbConnection(strconn))
            {
                //打开oledb连接
                conn.Open();
                //取sheet1的数据
                string strCom = "SELECT * FROM [Sheet1$]";
                OleDbDataAdapter myadapter = new OleDbDataAdapter(strCom, conn);
                myadapter.Fill(ds);
            }
            DataTable dt = ds.Tables[0];
            for (int i = 0; i < 24; i++)
            {
                if (airconditionLoad[i] != 0)
                {
                    try
                    {
                        DataRow[] rows = dt.Select("CLFT +1 > " + CLFT.ToString() + "AND CLFT <" + CLFT.ToString() + "and CAP > " + airconditionLoad[i] / 3);
                        DataRow desRow = rows[0];
                        foreach (DataRow row in rows)
                        {
                            if ((double)row["CAP"] < (double)desRow["CAP"])
                            {
                                desRow = row;
                            }
                        }
                        Cost[i] = (double)desRow["Inp Pwr"] * 3;
                    }
                    catch (Exception)
                    {

                        throw;
                    }
                }
            }
            return Cost;

        }
        private double CalculateSingleDevice(int Loadpercent, int type)
        {
            double cost = 0;
            double FREEZEnCOOLINGPUMPCOST600RT = 67.7;
            double FREEZEnCOOLINGPUMPCOST1100RT = 111;
            ForeCastDataSetTableAdapters.tb_deviceCOPTableAdapter deviAdapter = new ForeCastDataSetTableAdapters.tb_deviceCOPTableAdapter();
            ForeCastDataSet.tb_deviceCOPDataTable deviDatatable = new ForeCastDataSet.tb_deviceCOPDataTable();
            if (Loadpercent > 20 && Loadpercent < 100)
            {
                int temp = Loadpercent / 10;
                int Upercent = temp * 10 + 10;
                int Lpercent = temp * 10;
                double Ucost, Lcost;
                //取得上下线最高最低负荷率
                deviDatatable = deviAdapter.GetDataByPCTnTYPE(Upercent.ToString(), type);
                ForeCastDataSet.tb_deviceCOPRow deviDatarow = (ForeCastDataSet.tb_deviceCOPRow)deviDatatable.Rows[0];
                Ucost = THREEMultiplay(deviDatarow.a, deviDatarow.b, deviDatarow.c, deviDatarow.d, CLFT);
                deviDatatable = deviAdapter.GetDataByPCTnTYPE(Lpercent.ToString(), type);
                deviDatarow = (ForeCastDataSet.tb_deviceCOPRow)deviDatatable.Rows[0];
                Lcost = THREEMultiplay(deviDatarow.a, deviDatarow.b, deviDatarow.c, deviDatarow.d, CLFT);
                //中间值线性求得
                temp = Loadpercent % 10;
                cost = (temp * Ucost + (10 - temp) * Lcost) / 10;

            }
            else
            {
                if (Loadpercent <= 20)
                {
                    deviDatatable = deviAdapter.GetDataByPCTnTYPE("20", type);
                    ForeCastDataSet.tb_deviceCOPRow deviDatarow = (ForeCastDataSet.tb_deviceCOPRow)deviDatatable.Rows[0];
                    cost = THREEMultiplay(deviDatarow.a, deviDatarow.b, deviDatarow.c, deviDatarow.d, CLFT);
                    cost = cost * Loadpercent / 20;
                }
                else
                {
                    deviDatatable = deviAdapter.GetDataByPCTnTYPE("100", type);
                    ForeCastDataSet.tb_deviceCOPRow deviDatarow = (ForeCastDataSet.tb_deviceCOPRow)deviDatatable.Rows[0];
                    cost = THREEMultiplay(deviDatarow.a, deviDatarow.b, deviDatarow.c, deviDatarow.d, CLFT);
                    cost = cost * Loadpercent / 100;
                }
            }
            if (type == 1)//开启水泵的消耗
            {
                cost = cost + FREEZEnCOOLINGPUMPCOST600RT;
            }
            else
            {
                cost = cost + FREEZEnCOOLINGPUMPCOST1100RT;
            }
            return cost;
        }
        private double THREEMultiplay(double a, double b, double c, double d, double X)
        {
            double result = 0;
            result = a * X * X * X + b * X * X + c * X + d;
            return result;

        }
        private double[] CalculateNORMALCostELECooling(double[] electCoolingLoad)
        {
            double[] Cost = new double[24];

            try
            {
                for (int i = 0; i < 24; i++)
                {
                    if (electCoolingLoad[i] > 0)
                    {
                        if (electCoolingLoad[i] < POWER600RT)
                        {//一小
                            int percentload = (int)(electCoolingLoad[i] * 100 / POWER600RT);
                            Cost[i] = CalculateSingleDevice(percentload, 1);
                        }
                        else if (electCoolingLoad[i] > POWER600RT && electCoolingLoad[i] < POWER600RT + POWER1100RT)
                        {//一大一小
                            int percentLoad = (int)(electCoolingLoad[i] * 100 / (POWER600RT + POWER1100RT));

                            Cost[i] = CalculateSingleDevice(percentLoad, 1) + CalculateSingleDevice(percentLoad, 2);
                        }
                        else if (electCoolingLoad[i] > POWER600RT + POWER1100RT && electCoolingLoad[i] < POWER1100RT + POWER1100RT)
                        {//两大
                            int percentLoad = (int)(electCoolingLoad[i] * 100 / (POWER1100RT + POWER1100RT));

                            Cost[i] = CalculateSingleDevice(percentLoad, 1) + CalculateSingleDevice(percentLoad, 2);
                        }
                        else if (electCoolingLoad[i] > POWER1100RT + POWER1100RT && electCoolingLoad[i] <= POWER600RT + POWER1100RT + POWER1100RT)
                        {//全开
                            int percentLoad = (int)(electCoolingLoad[i] * 100 / (POWER600RT + POWER1100RT + POWER1100RT));
                            Cost[i] = CalculateSingleDevice(percentLoad, 1) + 2 * CalculateSingleDevice(percentLoad, 2);
                        }
                    }
                    else
                    {
                        Cost[i] = 0;
                    }
                }

            }
            catch (Exception)
            {

                throw;
            }
            return Cost;
        }

        //public  DataTable CalculateCost()
        //{
        //    ElectricCooling smallEleCooling = new ElectricCooling(1);//一个小的
        //    ElectricCooling bigEleCooling = new ElectricCooling(2);//两个大的
        //    IceStorage iceStorage = new IceStorage();//一个冰蓄冷机组
        //    HeatPump heatPump = new HeatPump();//地缘热本
        //    LBPump lbPump = new LBPump();//溴化锂泵
        //    double[] curLoad = new double[24];//备份当前负荷
        //    for (int i = 0; i < 24; i++)
        //    {
        //        curLoad[i] = DLOADS[i];
        //    }
        //    for (int i = 0; i < 24; i++)
        //    {
        //        if
        //    }
        //}

        //实际优化
        //public DataTable Calculate1(bool ifOPT)
        //{
        //    int[] Seque;
        //    double rest = 0;
        //    int endtime = 0;
        //    int endminute = 0;
        //    int[] OptSeque1 = { 8, 9, 10, 13, 14, 15, 16, 17, 11, 12, 7, 6, 22, 23, 0, 1, 2, 3, 4, 5, 18, 19, 20, 21 };//时间优先级序列
        //    SUM_ICESTORAGE = 92888 - 13950;
        //    //int[] OptSeque1 = { 8, 9, 10, 13, 14, 15, 16, 17, 11, 12, 21, 7, 6, 22, 23, 0, 1, 2, 3, 4, 5 };//时间优先级序列1
        //    //int[] OptSeque2 = { 18, 19, 20 };//时间优先级序列2

        //    if (ifOPT)
        //    {
        //        Seque = OptSeque1;
        //    }
        //    else
        //    {
        //        Seque = NorSeque;
        //    }
        //    double[] curLoad = new double[24];//[5]=[总负荷][冰蓄冷供应][电制冷供应][常驻能源供应][双工况]
        //    double[] deicingLoad = new double[24];//[5]=[总负荷][冰蓄冷供应][电制冷供应][常驻能源供应][双工况]
        //    double[] electCoolingLoad = new double[24];//[5]=[总负荷][冰蓄冷供应][电制冷供应][常驻能源供应][双工况]
        //    double[] pumpLoad = new double[24];//[5]=[总负荷][冰蓄冷供应][电制冷供应][常驻能源供应][双工况]
        //    double[] airconditionLoad = new double[24];//[5]=[总负荷][冰蓄冷供应][电制冷供应][常驻能源供应][双工况]
        //    double[] icingLoad = new double[24]{
        //    11817,11817,11817,11817,11817,11817,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11817,11817};//[制冰负荷]
        //    double[] icingCost = new double[24]{
        //    2981.079,2981.079,2981.079,2981.079,2981.079,2981.079,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2981.079,2981.079};//[制冰能耗]

        //    //当前负荷
        //    for (int i = 0; i < 24; i++)
        //    {
        //        curLoad[i] = DLOADS[i];
        //    }
        //    double icestorageREST = SUM_ICESTORAGE;
        //    bool ifGetCut = false;
        //    #region//满足峰时用电
        //    for (int i = 0; i < Seque.Length; i++)
        //    {
        //        double temp = curLoad[Seque[i]];
        //        if (temp > LBPUMP + HEATPUMP)
        //        {
        //            temp = temp - LBPUMP - HEATPUMP;
        //            double icecool;
        //            //冰蓄冷是否能开
        //            if (Seque[i] >= 22 || Seque[i] < 6)//期间开启蓄冰工况
        //            {
        //                icecool = 0;
        //            }
        //            else
        //            {

        //                //冰蓄冷是否还能全开
        //                if (icestorageREST > COOLING_ICESTORAGE)
        //                {
        //                    icecool = COOLING_ICESTORAGE;
        //                }
        //                else
        //                {
        //                    icecool = icestorageREST;
        //                }
        //            }


        //            if (Seque[i] == 18)
        //            {
        //                deicingLoad[18] = temp;
        //                rest = 13950 - temp;
        //                electCoolingLoad[18]=0;
        //                airconditionLoad[18]=0;
        //            }
        //            else if (Seque[i] == 19)
        //            {
        //                deicingLoad[19] = temp;
        //                rest = rest - temp;
        //                electCoolingLoad[19]=0;
        //                airconditionLoad[19]=0;
        //            }
        //            else if (Seque[i] == 20)
        //            {
        //                if (rest > temp)
        //                {
        //                    deicingLoad[20] = temp;
        //                    rest = rest - temp;
        //                    electCoolingLoad[20]=0;
        //                    airconditionLoad[20]=0;
        //                }
        //                else
        //                {
        //                    endtime = 20;
        //                    endminute = (int)(rest / temp * 60);
        //                    deicingLoad[20] = rest;
        //                    temp = temp - rest;
        //                    rest = 0;
        //                    electCoolingLoad[20] = temp;
        //                    airconditionLoad[20] = 0;          
        //                }
        //            }
        //            else if (Seque[i] == 21)
        //            {
        //                //if (rest == 0)
        //                //{
        //                //    deicingLoad[21] = 0;
        //                //    electCoolingLoad[21] = temp;
        //                //    airconditionLoad[21] = 0;
        //                //}
        //                //else
        //                //{
        //                //    endtime = 21;
        //                //    endminute = (int)(rest / temp-1991 * 60);
        //                //    deicingLoad[21] = rest;
        //                //    temp = temp - rest;
        //                //    electCoolingLoad[21] = temp;
        //                //    airconditionLoad[21] = 0;
        //                //}

        //                if (rest > temp)
        //                {
        //                    deicingLoad[21] = temp;
        //                    rest = rest - temp;
        //                    electCoolingLoad[21] = 0;
        //                    airconditionLoad[21] = 0;
        //                    endtime = 22;
        //                    endminute = 00;
        //                }
        //                else
        //                {
        //                    endtime = 21;
        //                    endminute = (int)(rest / temp * 60);
        //                    deicingLoad[21] = rest;
        //                    temp = temp - rest;
        //                    rest = 0;
        //                    electCoolingLoad[21] = temp;
        //                    airconditionLoad[21] = 0;
        //                }
        //            }



        //            else
        //            {
        //                //是否需要电制冷
        //                if (temp > icecool)
        //                {

        //                    temp -= icecool;
        //                    icestorageREST -= icecool;
        //                    deicingLoad[Seque[i]] = icecool;
        //                    if (temp > COOLING_ELE)
        //                    { //是否需要双工况

        //                        electCoolingLoad[Seque[i]] = COOLING_ELE;
        //                        airconditionLoad[Seque[i]] = temp - COOLING_ELE;
        //                    }
        //                    else
        //                    {

        //                        electCoolingLoad[Seque[i]] = temp;
        //                        airconditionLoad[Seque[i]] = 0;
        //                    }
        //                }
        //                else
        //                {
        //                    deicingLoad[Seque[i]] = temp;
        //                    electCoolingLoad[Seque[i]] = 0;
        //                    airconditionLoad[Seque[i]] = 0;
        //                    icestorageREST -= temp;
        //                }
        //            }
        //        }
        //            else
        //            {
        //                deicingLoad[Seque[i]] = 0;
        //                electCoolingLoad[Seque[i]] = 0;
        //                airconditionLoad[Seque[i]] = 0;
        //            }


        //        if (icestorageREST == 0 && ifGetCut == false)//此时预计融冰结束
        //        {
        //            CutTime = Seque[i];
        //            CutMinute = (int)((deicingLoad[Seque[i]] / COOLING_ICESTORAGE) * 60);
        //            ifGetCut = true;

        //        }
        //            pumpLoad[Seque[i]] = LBPUMP + HEATPUMP;//地源热泵和溴化锂常开\
        //            pumpLoad[23] = 0;
        //            pumpLoad[22] = 0;
        //            pumpLoad[0] = 0;
        //            pumpLoad[1] = 0;
        //            pumpLoad[2] = 0;
        //            pumpLoad[3] = 0;
        //            pumpLoad[4] = 0;
        //            pumpLoad[5] = 0;

        //        }
        //    #endregion
        //        #region//根据得出的冷量计算每小时制冷方式的能耗
        //        double[] airconditionCost = CalculateCostAIRConditon(airconditionLoad);
        //        double[] electCoolingCost;
        //        if (ifOPT)
        //        {
        //            //electCoolingLoad[CutTime] = (electCoolingLoad[CutTime] * 60) / (60 - CutMinute);
        //            electCoolingCost = CalculateOPTCostELECooling(electCoolingLoad);
        //            electCoolingCost[CutTime] = electCoolingCost[CutTime] * (60 - CutMinute) / 60;
        //            ///////////////////////////////////////////////////
        //            //////////////////////////////////////
        //            ////////////////////////////////
        //            ////////////////////这里有大问题，考虑开关节点及能耗

        //            //electCoolingLoad[CutTime] = (electCoolingLoad[CutTime] / 60) * (60 - CutMinute);

        //        }
        //        else
        //        {
        //            electCoolingCost = CalculateNORMALCostELECooling(electCoolingLoad);
        //        }
        //        #endregion


        //        DataTable ResultTable = new DataTable();
        //        ResultTable.Columns.Add("时间节点", typeof(string));
        //        ResultTable.Columns.Add("电价", typeof(string));
        //        ResultTable.Columns.Add("需求负荷", typeof(string));
        //        ResultTable.Columns.Add("冰蓄冷融冰工况", typeof(string));
        //        ResultTable.Columns.Add("电制冷", typeof(string));
        //        ResultTable.Columns.Add("电制冷耗能", typeof(string));
        //        ResultTable.Columns.Add("常驻冷源", typeof(string));
        //        ResultTable.Columns.Add("冰蓄冷空调工况", typeof(string));
        //        ResultTable.Columns.Add("空调工况耗能", typeof(string));
        //        ResultTable.Columns.Add("冰蓄冷制冰工况", typeof(string));
        //        ResultTable.Columns.Add("制冰工况耗能", typeof(string));
        //        ResultTable.Columns.Add("总能耗", typeof(string));
        //        ResultTable.Columns.Add("每小时电费", typeof(string));
        //        double[] tempCost = new double[24];
        //        double[] totalCost = new double[24];
        //        double[] tempsum = { 0, 0, 0, 0, 0, 0, 0, 0 };//需求总负荷 溶冰提供总负荷 电制冷提供总符合 
        //        //电制冷总能耗 空调提供总负荷，空调总能耗，系统总能耗，系统总电价
        //        for (int i1 = 0; i1 < 24; i1++)
        //        {
        //            tempCost[i1] = airconditionCost[i1] + electCoolingCost[i1] + icingCost[i1];
        //            totalCost[i1] = tempCost[i1] * ELEPRICE[i1];
        //            ResultTable.Rows.Add(new object[] { i1,                    
        //           ELEPRICE[i1].ToString(), 
        //           curLoad[i1].ToString("0.0"),
        //           deicingLoad[i1].ToString("0.0"),
        //           electCoolingLoad[i1].ToString("0.0"),//电制冷量
        //           electCoolingCost[i1].ToString("0.0"),
        //           pumpLoad[i1].ToString("0.0"),
        //           airconditionLoad[i1].ToString("0.0"), //空调工况
        //           airconditionCost[i1].ToString("0.0"),
        //           icingLoad[i1].ToString("0.0"),//制冰工况
        //           icingCost[i1].ToString("0.0"),
        //           tempCost[i1].ToString("0.0"),
        //           totalCost[i1].ToString("0.000")
        //        });
        //            //加总
        //            tempsum[0] += curLoad[i1];
        //            tempsum[1] += deicingLoad[i1];
        //            tempsum[2] += electCoolingLoad[i1];
        //            tempsum[3] += electCoolingCost[i1];
        //            tempsum[4] += airconditionLoad[i1];
        //            tempsum[5] += airconditionCost[i1];
        //            tempsum[6] += tempCost[i1];
        //            tempsum[7] += totalCost[i1];
        //        }
        //        ResultTable.Rows.Add(new object[] { "总计", "冰蓄冷融冰结束时间：" + endtime.ToString() + " :" + endminute.ToString(), tempsum[0].ToString("0.0"), tempsum[1].ToString("0.0"), tempsum[2].ToString("0.0"), tempsum[3].ToString("0.0"), "31856.0", tempsum[4].ToString("0.0"), tempsum[5].ToString("0.0"), "94536.0", "23848.0", tempsum[6].ToString("0.0"), tempsum[7].ToString("0.000") });
        //        return ResultTable;

        //    }
        }
    }
